﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ToyStore.Infrastructure;
using ToyStore.Domain.Store;

namespace ToyStore.Web.Mvc.Controllers
{

    public class CategoryController : Controller
    {
        /// <summary>
        /// Dostep do bazy danych kategorii.
        /// </summary>
        private readonly IExRepository<Category> _categoryRepository;
        /// <summary>
		/// Konstruktor.
		/// </summary>
		/// <param name="userRepository"></param>
        public CategoryController(IExRepository<Category> categoryRepository)
    	{
            _categoryRepository = categoryRepository;
    	}

        //
        // GET: /Category/

        public ActionResult Index()
        {

          
            return View();
        }
        //
        // GET: /Category/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Category/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Category/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /Category/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Category/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Category/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Category/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        /// <summary>
        /// Renderuje mnenu kategorii
        /// </summary>
        /// <returns></returns>
        public ActionResult GenerateCategoryMenu()
        {

            var categoryList = _categoryRepository.GetQuery().AsEnumerable();
            return PartialView("_CategoryMenu", categoryList);
        }
    }
}
